// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.components.tapbb;

import lichen.services.LichenModule;
import lichen.services.UserService;

import org.apache.tapestry.TapestryConstants;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.services.Request;

/**
 * 论坛的phpbb3风格的layout
 * 
 * @author <a href="mailto:tapestry5@gmail.com">Jim</a>
 * @version $Revision: 102 $
 * @since 0.0.1
 */
public class Layout {
	public Layout() {
		_context = request.getContextPath();
	}

	@Inject
	private Request request;
	/**
	 * 设定当前context并cache住
	 */
	@Persist
	private String _context;

	public String getContext() {
		return _context;
	}

	/**
	 * 设定当前页面的title信息
	 */
	@Parameter(defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX)
	private String _title;

	@Inject
	private SymbolSource symbolSource;

	/** 表头信息 * */
	private String _logInfo;

	@Inject
	private UserService userService;

	/**
	 * 得到展示的标题文字.
	 * 
	 * @return 页面的标题文字.
	 */
	public String getTitle() {

		if (_title == null && _logInfo != null) {
			_title = _logInfo;
		}
		return this._title;
	}

	public long getOnlineUserNum() {
		return userService.getOnlineUserNum();
	}

	public String getVersion() {
		// TODO tapestyr 使用 @Inject @Value 目前还有问题，所以只好采用折中的方式
		return symbolSource.expandSymbols("${"
				+ LichenModule.LICHEN_VERSION_KEY_NAME + "}");
	}

}